local function getupvaluetable(func, inname)
    local i = 1
    while true do
        local name, value = debug.getupvalue(func, i)
        if name == nil then
            return
        end
        
        if name == inname then
            return i,value
        end
        
        i=i+1
    end
end
local _, cmd = getupvaluetable(hf_modules.card_king_rank.start,'CMD')
local _, old_update_func = getupvaluetable(cmd.start,'update_robot')
local idx, old_update_robot_value_func = getupvaluetable(old_update_func,'update_robot_value')
local _, math_random = getupvaluetable(old_update_robot_value_func,'math_random')
local _,update_rank = getupvaluetable(old_update_robot_value_func,'update_rank')

local function new_update_robot_value(curr_time)
    if hf_modules.card_king_rank.next_robot_update_time < curr_time then
        for id,info in pairs(hf_modules.card_king_rank.robots_list) do
            --涨5~50分（5的倍数）
            if info.curr_value < info.max_value then
                local add_value = math_random(1,10) * 5
                if add_value > info.max_value - info.curr_value then
                    add_value = info.max_value - info.curr_value
                end
                
                info.curr_value = info.curr_value + add_value
                update_rank(info.id,info.curr_value)
            end
        end
        --下次刷新时间为1~5分钟
        local random_value = math_random(2,2)
        hf_modules.card_king_rank.next_robot_update_time = curr_time + math_random(2,2) * 1
        dbglog("@@@@@@@@next_robot_update_time",random_value,hf_modules.card_king_rank.next_robot_update_time,curr_time)
        print_r(hf_modules.card_king_rank.robots_list)
    end

    --print(next_robot_update_time,curr_time)
end

debug.setupvalue(old_update_func,idx,new_update_robot_value)
